﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQuarters.WebQuarters.Utils;

namespace OpenQuarters.WebQuarters.Modules.Blog
{
    partial class BlogInstance : BlogEntity<BlogInstance, long>
    {
        public override long GetKey(BlogInstance Entity)
        {
            return Entity.BlogInstanceId;
        }

        public override System.Linq.Expressions.Expression<Func<BlogInstance, bool>> GetIDSelector(long ID)
        {
            return e => e.BlogInstanceId == ID;
        }

        public static FriendlyDictionary<string, string> BlogInstances
        {
            get
            {
                var r = new FriendlyDictionary<string, string>();
                Table.ToList().ForEach(e => r[e.BlogInstanceId.ToString()] = e.Name);
                return r;
            }
        }

        public static BlogInstance GetByName(string name)
        {
            return Table.FirstOrDefault(i => i.Name == name);
        }
    }
}
